package LeetCodestudy;

public class Test {
    //统计字符串中的单词个数，这里的单词指的是连续的不是空格的字符。
    //正确方法：
    public int countSegments(String s) {
        int segmentCount = 0;

        for (int i = 0; i < s.length(); i++) {
            if ((i == 0 || s.charAt(i - 1) == ' ') && s.charAt(i) != ' ') {
                segmentCount++;
            }
        }

        return segmentCount;
    }

    public int countSegments1(String s) {
        //结果错误 无法正确识别“”字符串
        String[] str2 = s.split(" ");
        int len = str2.length;
        return len;
    }


    public static void main(String[] args) {
        Test test=new Test();
        String s2="abc hew dad";
        System.out.println(test.countSegments(s2));


    }
}
    //将大写字符转成小写字符
/*    public String toLowerCase(String s) {
        String str2=s.toLowerCase();
        return str2;

    }

    public static void main1(String[] args) {
        String str="hELLO";
        String s=str.toLowerCase();
        System.out.println(s);
    }
}
  */